<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务，帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件，不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\api\model\jia;

use app\common\model\jia\Survey as SurveyModel;
use app\api\service\User as UserService;
/**
 * 文章分类模型
 * Class Survey
 * @package app\api\model\article
 */
class Survey extends SurveyModel {
	/**
	 * 隐藏字段
	 * @var array
	 */
	protected $hidden = [
		'is_delete',
		'store_id',
		'update_time',
	];

	public function getList() {

		$list = $this
			->where('status', 1)

			->order('sort asc')

			->select()->toArray();

		return $list;
	}

	public function add(array $list) {
		// 当前用户信息
		$user = UserService::getCurrentLoginUser(true);
		$score = 0;
		foreach ($list as $key => $value) {
			if ($value['score'] > 0) {
				$score += $value['score'];
				switch ($value['score']) {
				case 10:
					$list[$key]['answer'] = '满意';
					break;
				case 8:
					$list[$key]['answer'] = '较满意';
					break;
				case 6:
					$list[$key]['answer'] = '一般';
					break;
				case 4:
					$list[$key]['answer'] = '不好';
					break;
				case 2:
					$list[$key]['answer'] = '很差';
					break;
				default:
					// code...
					break;
				}
			}
		}

		$this->save([
			'user_id' => $user['user_id'],
			'score' => $score,

			'content' => json_encode($list),

			'store_id' => self::$storeId,
		]);

		return true;
	}
}
